package com.halixun.d2app.dialog;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.halixun.d2app.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class ExitFragment extends DialogFragment {

    private ExitDialogListener mListener;

    public ExitFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_exit, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setListeners(view);
    }

    private void setListeners(View view) {
        view.findViewById(R.id.cancel).setOnClickListener(v -> dismiss());
        view.findViewById(R.id.confirm).setOnClickListener(v -> {
            if (null != mListener) {
                mListener.onExitDialogClickListener();
                dismiss();
            }
        });
    }

    public void setExitDialogListener(ExitDialogListener listener) {
        this.mListener = listener;
    }

    public interface ExitDialogListener {
        void onExitDialogClickListener();
    }
}
